extends CharacterBody2D

class_name Enemy

# 移动速度
@export var speed : int = 0

# 目标角色
var target : CharacterBody2D
var time_counter : float = 5
var rand_direction = Vector2(100,100)

@onready var graphics: Node2D = $Graphics
@onready var state_machine: StateMachine = $StateMachine

# 成功命中
signal successfully_hit


func  _physics_process(delta):
	if time_counter > 5:
		rand()
		time_counter = 0
	time_counter += delta
	if (target.global_position-self.global_position).length()<20:
		successfully_hit.emit()
		set_physics_process(false)
		$Timer.start()
	pass



func rand()->void:
	var random = RandomNumberGenerator.new()
	random.randomize()
	rand_direction = Vector2(random.randf_range(-1,1),random.randf_range(-1,1))
	rand_direction = rand_direction.normalized()


func _on_timer_timeout() -> void:
	$Timer.stop()
	set_physics_process(true)
	pass # Replace with function body.
